package com.scribbles.admin.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.googlecode.ehcache.annotations.Cacheable;
import com.scribbles.admin.dao.LookupTypeDAO;
import com.scribbles.common.entity.LookupType;

@Service
public class LookupService {
	@Autowired
	private LookupTypeDAO lookupTypeDAO;

	/**
	 * Method createLookupType.
	 * @param lookupType LookupType
	 */
	@Transactional
	public void createLookupType(LookupType lookupType) {
		lookupTypeDAO.create(lookupType);
	}
	/**
	 * Method updateLookupType.
	 * @param lookupType LookupType
	 * @return LookupType
	 */
	@Transactional
	public LookupType updateLookupType(LookupType lookupType) {
		LookupType lookupTypeManaged = lookupTypeDAO.findByPrimaryKey(lookupType.getId());
		lookupTypeManaged.setName(lookupType.getName());
		lookupTypeManaged.setUpdatedBy(lookupType.getUpdatedBy());
		lookupTypeManaged.setUpdatedDate(new Date());
		return lookupTypeManaged;
	}
	/**
	 * Method removeLookupType.
	 * @param id Integer
	 */
	@Transactional
	public void removeLookupType(Integer id) {
		lookupTypeDAO.remove(lookupTypeDAO.getReference(id));
	}
	
	/**
	 * Method retrieveLookupTypes.
	 * @return List<LookupType>
	 */
	@Cacheable(cacheName="dropdownCache")
	public List<LookupType> retrieveLookupTypes() {
		List<LookupType> lookupTypes = lookupTypeDAO.findAll();
		return lookupTypes;
	}
	/**
	 * Method testCriteriaAPIretrieveLookupTypes.
	 * @return List<Object>
	 */
	public List<Object> testCriteriaAPIretrieveLookupTypes() {
		return lookupTypeDAO.findAllUsingCriteriaAPI();
	}
}
